package o;

import android.annotation.TargetApi;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInstaller;
import android.content.pm.PackageInstaller.Session;
import android.content.pm.PackageInstaller.SessionParams;
import com.huawei.appgallery.packagemanager.api.bean.ManagerTask;
import com.huawei.appgallery.packagemanager.impl.uninstall.control.UninstallResultReceiver;
import com.huawei.hwid.core.constants.HwAccountConstants;
import java.io.IOException;

@TargetApi(24)
public class cpw {
    public static void ˋ(Context context, ManagerTask managerTask) {
        PackageInstaller packageInstaller = context.getPackageManager().getPackageInstaller();
        int ˊ = ˊ(packageInstaller, managerTask.packageName);
        if (ˊ == 0) {
            cnu.ˏ.ˊ("RemoveSplitProcess", "uninstallSplitApk Session ID == 0, Create feature Session Error!");
            ˊ(context, managerTask, -10001);
            return;
        }
        try {
            Session openSession = packageInstaller.openSession(ˊ);
            Object obj = null;
            for (String str : managerTask.splitNames) {
                Object obj2;
                try {
                    openSession.removeSplit(str);
                    obj2 = 1;
                } catch (IOException e) {
                    cnu.ˏ.ˊ("RemoveSplitProcess", "remove split error:" + str);
                    obj2 = obj;
                }
                obj = obj2;
            }
            if (obj != null) {
                Intent intent = new Intent(context, UninstallResultReceiver.class);
                intent.putExtra("package_task_result_receiver_packagename", managerTask.packageName);
                intent.putExtra("package_task_result_receiver_taskid", managerTask.taskId);
                intent.setPackage(context.getPackageName());
                openSession.commit(PendingIntent.getBroadcast(context, managerTask.packageName.hashCode(), intent, HwAccountConstants.FLAG_TRANS_NAVIGATION_BAR).getIntentSender());
                return;
            }
            ˊ(context, managerTask, -10003);
        } catch (IOException e2) {
            cnu.ˏ.ˊ("RemoveSplitProcess", "openSession error:" + ˊ);
            ˊ(context, managerTask, -10002);
        }
    }

    private static int ˊ(PackageInstaller packageInstaller, String str) {
        int i = 0;
        try {
            SessionParams sessionParams = new SessionParams(2);
            sessionParams.setAppPackageName(str);
            cos.ॱ(sessionParams);
            i = packageInstaller.createSession(sessionParams);
        } catch (IOException e) {
            cnu.ˏ.ˊ("RemoveSplitProcess", "createSession packageName : " + str + " error");
        }
        cnu.ˏ.ˋ("RemoveSplitProcess", "createSession packageName : " + str + " sessionId : " + i);
        return i;
    }

    private static void ˊ(Context context, ManagerTask managerTask, int i) {
        cnu.ˏ.ˋ("RemoveSplitProcess", "removeSplitFailed pkg :" + managerTask.packageName + ",returnCode:" + -5);
        cph.ॱ(context).ˋ(managerTask.packageName, 9, cnz.NOT_HANDLER, i, 5, managerTask.taskId, cod.UNINSTALL);
    }
}
